/**
 * @description 滚动高度
 */

import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const useScrollTopStore = defineStore('scrollTop', () => {
    let scrollTop = ref(0)
    let istop = computed(() => scrollTop.value === 0)
    let timer = null

// 滚动事件处理函数
const handleScroll = (event,centerDiv) => {
    event.preventDefault()
    const scrollAmount = event.deltaY * 0.3 // 0.5 表示减半滚动速度
    if (centerDiv.value) {
      centerDiv.value.scrollTop += scrollAmount // 垂直滚动
      // console.log(centerDiv.value.scrollTop)
    }
    if(!timer) {
        timer = setTimeout(() => {
            scrollTop.value = centerDiv.value.scrollTop
            timer = null
        }, 300)     
    }
    return
  }
  
//鼠标移入图标，显示导航栏
const handleMouseEnter = () => {
    scrollTop.value = 0
    timer = 1
}

//鼠标移出图标
const handleMouseLeave = () => {
  timer = null
  console.log('timer',timer)
}
  
  return {
    scrollTop,
    istop,
    handleScroll,
    handleMouseEnter,
    handleMouseLeave
  }
})